<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
</head>
<body>
    <form id="loginForm">
        <label for="loginName">用户名:</label>
        <input type="text" id="loginName" name="loginName" required><br><br>

        <label for="password">密码:</label>
        <input type="password" id="password" name="password" required><br><br>

        <button type="submit" onclick="login(event)">登录</button>
    </form>

    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        function login(event) {
            // 阻止表单默认提交行为
            event.preventDefault();

            // 获取输入值
            const loginName = document.getElementById('loginName').value;
            const password = document.getElementById('password').value;

            // 使用axios发送GET请求
            axios.get('https://xshx.gufe.edu.cn/webchat/sysuser/login', {
                params: {
                    loginName,
                    password
                }
            })
            .then(response => {
                console.log(response);
                if (response.data.loginName != null) {
                    // password : Huax@2024
                    const userName = response.data.userName; 
                    console.log(response.data.userName);
                    alert('登录成功!!!!');
                    window.location.href = `index.html?userName=${userName}`;
                } else {
                  console.log(response.data.loginName)
                    alert('登录失败，请检查学号和密码！');
                }
            })
            .catch(error => {
                console.error('Error:', error);
            });
        }
    </script>
</body>
</html>